package com.sumainfor.pc.market.service;

import com.sumainfor.common.entity.ParentDeptVo;
import com.sumainfor.common.entity.SysUserVo;
import com.sumainfor.common.util.Arith;
import com.sumainfor.common.util.ContextUtils;
import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.ListMapMergeUtil;
import com.sumainfor.pc.market.dao.*;
import com.sumainfor.pc.market.feign.EpcFeign.EpcFeign;
import com.sumainfor.pc.market.feign.ZuulFeign.ZuulFeign;
import org.apache.commons.collections.MapUtils;
import org.omg.CORBA.OBJ_ADAPTER;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 功能描述:
 *
 * @Auther: zhlu
 * @Date: 2019/4/19 10:18
 * @Description:
 */
@Service
public class MarketWorkbenchService {

    Logger log= LoggerFactory.getLogger(MarketWorkbenchService.class);

    @Autowired
    MarketWorkbenchMapper MarketWorkbenchMapper;

    @Autowired
    SourceMapper SourceMapper;

    @Autowired
    OwnerMapper OwnerMapper;

    @Autowired
    ProfitMapper ProfitMapper;

    @Autowired
    TenantMapper TenantMapper;

    @Autowired
    EpcFeign EpcFeign;

    @Autowired
    ZuulFeign ZuulFeign;

    @Autowired
    CommunityMapper CommunityMapper;

    @Autowired
    RdPactMapper RdPactMapper;


    /**
     * 功能描述:
     * 统计业主来源占比
     * @Author zhlu
     * @Description //TODO
     * @Date 2018/11/14 17:43
     */
    public Map<String,Object>CountSource(Map<String,Object>params){
        Map<String,Object>result=new HashMap<String,Object>();
        List<String> SourceName=new ArrayList<String>();
        List<Map<String,Object>>CountSource=SourceMapper
                .CountSource(params);
        for(Map<String,Object> map:CountSource){
            SourceName.add(map.get("name").toString());
        }
        Integer CountOwner=OwnerMapper.CountOwner(params);
        result.put("CountSource",CountSource);
        result.put("CountOwner",CountOwner);
        result.put("SourceName",SourceName);
        return result;
    }

    /**
     * 功能描述:
     * 获取收房专员主页数据统计
     * 已通过盈利预测，已驳回盈利预测，审核中盈利预测，本月已收房，待联系业主
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/15 11:13
     */
    public Map<String,Object>getHouseCount(Map<String,Object>params){
        Map<String,Object>getHouseCount=MarketWorkbenchMapper.getHouseCount(params);
        return getHouseCount;
    }

    /**
     * 功能描述:
     * 根据当前收房专员编号获取个人收房走向
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/15 14:06
     */
    public Map<String,Object>getHouseInfoMap(Map<String,Object>params){
        Map<String,Object>getHouseInfoMap=new HashMap<String,Object>();
        getHouseInfoMap.put("HouTotal",ProfitMapper.getHouseInfoListCount(params));
        List<Map<String,Object>>getHouseInfoListObject=ProfitMapper.getHouseInfoList(params);
        //月份集合
        List<String>HouMonthList=new ArrayList<String>();
        //月付对应的收房总数
        List<String>HouValueList=new ArrayList<String>();
        if(getHouseInfoListObject.size()>0){
            for (Map<String,Object> map:getHouseInfoListObject){
                HouMonthList.add(map.get("HouMonth").toString());
                HouValueList.add(map.get("HouValue").toString());
            }
        }
        getHouseInfoMap.put("HouMonthList",HouMonthList);
        getHouseInfoMap.put("HouValueList",HouValueList);
        getHouseInfoMap.put("HouseInfoList",ProfitMapper.getHouseInfoList(params));
        return getHouseInfoMap;
    }

    /**
     * 功能描述:
     * 统计租客来源占比
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/11 17:29
     */
    public Map<String,Object>getTenantSourceCount(Map<String,Object>params){
        Map<String,Object>result=new HashMap<String,Object>();
        List<String>SourceName=new ArrayList<String>();
        List<Map<String,Object>>getTenantSourceCount=SourceMapper.getTenantSourceCount(params);
        for(Map<String,Object> map:getTenantSourceCount){
            SourceName.add(map.get("name").toString());
        }
        Integer CountTenant= TenantMapper.CountTenant(params);
        result.put("TenantSourceCount",getTenantSourceCount);
        result.put("CountTenant",CountTenant);
        result.put("SourceName",SourceName);
        return result;
    }

    /**
     * 功能描述:
     * 获取市场部经理的重要信息提醒
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/11 20:51
     */
    public Map<String,Object>getMatketManager(){
        Map<String,Object>getMatketManager=MarketWorkbenchMapper.getMatketManager();
        return getMatketManager;
    }

    /**
     * 功能描述:
     * 获取市场部经理的房源信息
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/16 20:08
     */
    public Map<String,Object>getMatketHousing(){
        Map<String,Object>getMatketHousing=ProfitMapper.getMatketHousing();
        JsonResult jsonResult = EpcFeign.getMatketRepairHousing();
        if(jsonResult.isSuccess()==false){
            getMatketHousing.put("housing6",0);
        }else{
            getMatketHousing.put("housing6",jsonResult.getResult());
        }
        //出租中
        double rentCount=Double.valueOf(getMatketHousing.get("rentCount").toString());
        //空置30天
        double allCount=Double.valueOf(getMatketHousing.get("allCount").toString());
        if(rentCount>0){
            getMatketHousing.put("housing8", Arith.mul(Arith.div(rentCount,allCount,2),100.00));
        }else{
            getMatketHousing.put("housing8",0);
        }
        return getMatketHousing;
    }

    /**
     * 功能描述:
     * 市场部经理各中心成交额
     * 市场部经理各中心带看
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/17 11:05
     */
    public Map<String,Object>getMatketTurnover(Map<String,Object>params){
        Map<String,Object>result=new HashMap<String,Object>();
        //各服务中心
        List<Map<String,Object>>getDeptList= ZuulFeign.getDeptList(new HashMap<String,Object>(){{
            put("type",3);//部门类型  1公司 2部门 3服务中心
        }});
        //市场部经理各中心成交额
        List<Map<String,Object>>getMatketTurnover=CommunityMapper.getMatketTurnover(params);
        //市场部经理各中心带看
        List<Map<String,Object>>getTakeAlook=CommunityMapper.getTakeAlook(params);
        //合并各中心成交额，各中心带看
        List<Map<String,Object>>Matket= ListMapMergeUtil.ListMergeUtils(getDeptList,getMatketTurnover,"DeptId");
        Matket=ListMapMergeUtil.ListMergeUtils(Matket,getTakeAlook,"DeptId");
        for(Map<String,Object> map:Matket){
            if(FieldCheckUtil.isMapFieldNotNull(map,new String[]{"Micount"})&&
                    FieldCheckUtil.isMapFieldNotNull(map,new String[]{"SeCount"})){
                map.put("count",Arith.add(map.get("Micount").toString(),map.get("SeCount").toString()).intValue());
            }else if(FieldCheckUtil.isMapFieldNotNull(map,new String[]{"Micount"})){
                map.put("count",Arith.add(map.get("Micount").toString(),"0").intValue());
                map.put("SeCount",0);
            }else if(FieldCheckUtil.isMapFieldNotNull(map,new String[]{"SeCount"})){
                map.put("count",Arith.add(map.get("SeCount").toString(),"0").intValue());
                map.put("Micount",0);
            }else{
                map.put("count",0);
                map.put("Micount",0);
                map.put("SeCount",0);
            }
        }
        //排序
        Collections.sort(Matket, new Comparator<Map<String, Object>>() {
            @Override
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                Integer count1=Integer.valueOf(o1.get("count").toString());
                Integer count2=Integer.valueOf(o2.get("count").toString());
                return count2.compareTo(count1);
            }
        });



        //只取10位最大
        List<Map<String,Object>>resultList=new ArrayList<Map<String,Object>>();
        for(int i=0;i<Matket.size();i++){
            System.err.println(Matket.get(i));
            if(i<=9){
                resultList.add(Matket.get(i));
            }
        }

        //排序
        Collections.sort(resultList, new Comparator<Map<String, Object>>() {
            @Override
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                Integer count1=Integer.valueOf(o1.get("count").toString());
                Integer count2=Integer.valueOf(o2.get("count").toString());
                return count1.compareTo(count2);
            }
        });

        //各服务中心名称
        List<String>chart1=new ArrayList<String>();
        //成交额
        List<String>chart2=new ArrayList<String>();
        //带看
        List<String>chart3=new ArrayList<String>();

        for(Map<String, Object> map:resultList){
            chart1.add(map.get("DeptName").toString());
            chart2.add(map.get("Micount").toString());
            chart3.add(map.get("SeCount").toString());
        }

        result.put("chart1",chart1);
        result.put("chart2",chart2);
        result.put("chart3",chart3);
        return result;
    }

    /**
     * 功能描述:
     * 服务中心经理重要信息提醒
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/18 14:25
     */
    public Map<String,Object>getMarketSerMeassage(){
        Map<String,Object>getMarketSerMeassage=MarketWorkbenchMapper.getMarketSerMeassage();
        return getMarketSerMeassage;
    }

    /**
     * 功能描述:
     * 本月中心成交排名
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/18 18:15
     */
    public Map<String,Object>getMarketUserClinch(){
        Map<String,Object>result=new HashMap<String,Object>();
        //所有人员
        JsonResult jsonResult=ZuulFeign.getAllUserIdAndName();
        List<Map<String,Object>>getAllUserIdAndName=(List<Map<String,Object>>)jsonResult.getResult();

        //各人员的成交
        List<Map<String,Object>>getMarketUserClinch=ProfitMapper.getMarketUserClinch();
        //各人员的带看
        List<Map<String,Object>>getMarketUserTakeAlook=ProfitMapper.getMarketUserTakeAlook();

        List<Map<String,Object>>UserList=ListMapMergeUtil.ListMergeUtils(getAllUserIdAndName,getMarketUserClinch,"userId");
        UserList=ListMapMergeUtil.ListMergeUtils(UserList,getMarketUserTakeAlook,"userId");

        for(Map<String,Object> map:UserList){
            if(FieldCheckUtil.isMapFieldNotNull(map,new String[]{"ClinchCount"})&&
                    FieldCheckUtil.isMapFieldNotNull(map,new String[]{"TakeCount"})){
                map.put("count",Arith.add(map.get("ClinchCount").toString(),map.get("TakeCount").toString()).intValue());
            }else if(FieldCheckUtil.isMapFieldNotNull(map,new String[]{"ClinchCount"})){
                map.put("count",Arith.add(map.get("ClinchCount").toString(),"0").intValue());
                map.put("TakeCount",0);
            }else if(FieldCheckUtil.isMapFieldNotNull(map,new String[]{"TakeCount"})){
                map.put("count",Arith.add(map.get("TakeCount").toString(),"0").intValue());
                map.put("ClinchCount",0);
            }else{
                map.put("count",0);
                map.put("ClinchCount",0);
                map.put("TakeCount",0);
            }
        }

        //排序
        Collections.sort(UserList, new Comparator<Map<String, Object>>() {
            @Override
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                Integer count1=Integer.valueOf(o1.get("count").toString());
                Integer count2=Integer.valueOf(o2.get("count").toString());
                return count2.compareTo(count1);
            }
        });


        //只取10位最大
        List<Map<String,Object>>resultList=new ArrayList<Map<String,Object>>();
        for(int i=0;i<UserList.size();i++){
            if(i<=9){
                resultList.add(UserList.get(i));
            }
        }

        //排序
        Collections.sort(resultList, new Comparator<Map<String, Object>>() {
            @Override
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                Integer count1=Integer.valueOf(o1.get("count").toString());
                Integer count2=Integer.valueOf(o2.get("count").toString());
                return count1.compareTo(count2);
            }
        });



        //各人员名称
        List<String>chart1=new ArrayList<String>();
        //成交额
        List<String>chart2=new ArrayList<String>();
        //带看
        List<String>chart3=new ArrayList<String>();

        for(Map<String, Object> map:resultList){
            chart1.add(map.get("UserName").toString());
            chart2.add(map.get("ClinchCount").toString());
            chart3.add(map.get("TakeCount").toString());
        }

        result.put("chart1",chart1);
        result.put("chart2",chart2);
        result.put("chart3",chart3);
        return result;
    }

    /**
     * 功能描述:
     * 服务中心经理待审核定价
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/18 14:43
     */
    public Integer getMarketSerPricing(){
        return ProfitMapper.getMarketSerPricing();
    }

    /**
     * 功能描述:
     * 服务中心经理需定价房源
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/18 14:58
     */
    public Integer getMarketSerNotPricing(){
        return ProfitMapper.getMarketSerNotPricing();
    }


    /** zc 修改
     *
     * 功能描述:
     * 服务中心经理需定价房源
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/18 14:58
     */
    public Integer getMarketSerNotPricNum(Map<String,Object> params) {
        List<Map<String,Object>> getMarketSerNotPricNum = ProfitMapper.getMarketSerNotPricNum(params);
        int sum = 0;
        if (getMarketSerNotPricNum.size()>0){
            for (Map<String, Object> zczsMap:getMarketSerNotPricNum) {
                if (MapUtils.getInteger(zczsMap,"RoomsNum")!=null){
                    sum = sum+MapUtils.getInteger(zczsMap,"RoomsNum");
                }
            }
        }
        return sum;
    }




    /**
     * 功能描述:
     * 服务中心经理中心房源情况
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/18 15:34
     */
    public Map<String,Object>getMarketSerCenter(Map<String,Object>params){
        Map<String,Object>getMarketSerCenter=ProfitMapper.getMarketSerCenter(params);
        Double Center3=Double.valueOf(getMarketSerCenter.get("Center3").toString());
        Double Center2=Double.valueOf(getMarketSerCenter.get("Center2").toString());
        //全部房间数大于0，空置房间数大于0
        if(Center3>0&&Center2>0){
            if(Center3>0){
                Double Center4=Arith.div(Center3,Center2,2);
                getMarketSerCenter.put("Center4",Center4);
            }
        }
        return getMarketSerCenter;
    }

    /**
     * 功能描述: 
     * 获取租赁顾问的重要状态提醒
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/19 10:19
     */
    public Map<String,Object> getMarketSalesStatus(Map<String,Object>params){
        return MarketWorkbenchMapper.getMarketSalesStatus(params);
    }

    /**
     * 功能描述: 
     * 获取租赁顾问的房源状态提醒
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/19 17:46
     */
    public Map<String,Object>getMarketSalesHouStatus(Map<String,Object> params)
    {
        return MarketWorkbenchMapper.getMarketSalesHouStatus(params);
    }

    /**
     * 功能描述: 
     * 获取租赁顾问的个人销售数据汇总
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/19 19:51
     */
    public Map<String,Object>getMarketSalesSummary(Map<String,Object>params){
        Map<String,Object> result=new HashMap<String,Object>();
        List<Map<String,Object>>getMarketSalesSummary=MarketWorkbenchMapper.getMarketSalesSummary(params);
        List<String>SalesDay=new ArrayList<String>();
        List<String>SalesDayVal=new ArrayList<String>();
        if(getMarketSalesSummary.size()>0){
            for (Map<String,Object> map:getMarketSalesSummary){
                SalesDay.add(map.get("Signing").toString());
                SalesDayVal.add(map.get("SigningVal").toString());
            }
        }
        result.put("SalesDay",SalesDay);
        result.put("SalesDayVal",SalesDayVal);
        return result;
    }

    /**
     * 功能描述: 
     * 获取租赁顾问的本月成交排名
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/20 11:37
     */
    public Map<String,Object>getMarketSalesHeart(Map<String,Object>params){
        Map<String,Object>result=new HashMap<String,Object>();

        SysUserVo userVo = ContextUtils.getSysUser();
        ParentDeptVo vo = null;
        for (int i = 0; i < userVo.getLength(); i++) {
            ParentDeptVo vo1 = userVo.getParentDeptVo();
            if (vo1.getType().equals(3)) {
                vo = vo1;
                break;
            }
        }
        //服务中心不为空
        if(vo!=null){
            params.put("deptId",vo.getDeptId());
        }

        //所有人员
        JsonResult jsonResult=ZuulFeign.getAllUserIdAndName();
        List<Map<String,Object>>getAllUserIdAndName=(List<Map<String,Object>>)jsonResult.getResult();

        //获取租赁顾问的本月中心成交
        List<Map<String,Object>>getMarketSalesClinch=MarketWorkbenchMapper.getMarketSalesClinch(params);
        //获取租赁顾问的本月带看记录
        List<Map<String,Object>>getMarketSalesBand=MarketWorkbenchMapper.getMarketSalesBand(params);

        List<Map<String,Object>>UserList=ListMapMergeUtil.ListMergeUtils(getAllUserIdAndName,getMarketSalesClinch,"userId");
        UserList=ListMapMergeUtil.ListMergeUtils(UserList,getMarketSalesBand,"userId");


        for(Map<String,Object> map:UserList){
            if(FieldCheckUtil.isMapFieldNotNull(map,new String[]{"heartCount"})&&
                    FieldCheckUtil.isMapFieldNotNull(map,new String[]{"bandCount"})){
                map.put("count",Arith.add(map.get("heartCount").toString(),map.get("bandCount").toString()).intValue());
            }else if(FieldCheckUtil.isMapFieldNotNull(map,new String[]{"heartCount"})){
                map.put("count",Arith.add(map.get("heartCount").toString(),"0").intValue());
                map.put("bandCount",0);
            }else if(FieldCheckUtil.isMapFieldNotNull(map,new String[]{"bandCount"})){
                map.put("count",Arith.add(map.get("bandCount").toString(),"0").intValue());
                map.put("heartCount",0);
            }else{
                map.put("count",0);
                map.put("heartCount",0);
                map.put("bandCount",0);
            }
        }

        //排序
        Collections.sort(UserList, new Comparator<Map<String, Object>>() {
            @Override
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                Integer count1=Integer.valueOf(o1.get("count").toString());
                Integer count2=Integer.valueOf(o2.get("count").toString());
                return count2.compareTo(count1);
            }
        });

        String userId=null;
        //排名
        for(int i=0;i<UserList.size();i++){
            userId=UserList.get(i).get("userId").toString();
            log.info("UserList----"+UserList.get(i));
            log.info("ContextUtils.getUserId()----"+ContextUtils.getUserId());
            if(userId.equals(ContextUtils.getUserId().toString())){
                result.put("order",i+1);
                break;
            }
        }

        //只取10位最大
        List<Map<String,Object>>resultList=new ArrayList<Map<String,Object>>();
        for(int i=0;i<UserList.size();i++){
            if(i<=9){
                resultList.add(UserList.get(i));
            }
        }

        //排序
        Collections.sort(resultList, new Comparator<Map<String, Object>>() {
            @Override
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                Integer count1=Integer.valueOf(o1.get("count").toString());
                Integer count2=Integer.valueOf(o2.get("count").toString());
                return count1.compareTo(count2);
            }
        });

        //各人员名称
        List<String>chart1=new ArrayList<String>();
        //成交额
        List<String>chart2=new ArrayList<String>();
        //带看
        List<String>chart3=new ArrayList<String>();

        for(Map<String, Object> map:resultList){
            chart1.add(map.get("UserName").toString());
            chart2.add(map.get("heartCount").toString());
            chart3.add(map.get("bandCount").toString());
        }

        result.put("chart1",chart1);
        result.put("chart2",chart2);
        result.put("chart3",chart3);
        return result;
    }

    /**
     * 功能描述: 
     * 获取租赁顾问的本月成交率
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/21 12:42
     */
    public Map<String,Object>getMarketSalesClinchMonth(Map<String,Object>params){
        Map<String,Object>result=new HashMap<String,Object>();
        params.put("UserId",ContextUtils.getUserId());
        //获取租赁顾问的本月成交
        List<Map<String,Object>>getMarketSalesClinchMonth=MarketWorkbenchMapper.getMarketSalesClinchMonth(params);

        List<String>chart1=new ArrayList<>();
        List<String>chart2=new ArrayList<>();
        if(getMarketSalesClinchMonth.size()>0){
            for(Map<String,Object> map:getMarketSalesClinchMonth){
                chart1.add(map.get("clinchDay").toString());
                chart2.add(map.get("clinchCount").toString());
            }
        }
        result.put("chart1",chart1);
        result.put("chart2",chart2);
        return result;
    }

    /**
     * 功能描述: 
     * 本月公司成交排名
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/22 11:01
     */
    public Map<String,Object>getMarketSalesClinchCom(Map<String,Object>params){
        Map<String,Object>result=new HashMap<String,Object>();
        //服务中心
        params.put("type",3);
        //获取当前用户下所有的服务中心
        List<Map<String,Object>>getDeptList=ZuulFeign.getDeptList(params);
        List<String>DeptIdList=new ArrayList<>();
        if(getDeptList.size()>0){
            for(Map<String,Object> map:getDeptList){
                log.info("map-------------"+map);
                DeptIdList.add(map.get("DeptId").toString());
            }
        }
        //所有服务中心编号
        params.put("DeptIdList",DeptIdList);

        //所有人员
        JsonResult jsonResult=ZuulFeign.getAllUserIdAndName();
        List<Map<String,Object>>getAllUserIdAndName=(List<Map<String,Object>>)jsonResult.getResult();

        //获取销售顾问本月公司成交
        List<Map<String,Object>>getMarketSalesClinchCom=MarketWorkbenchMapper.getMarketSalesClinchCom(params);
        //获取销售顾问本月公司带看记录
        List<Map<String,Object>>getMarketSalesBandCom=MarketWorkbenchMapper.getMarketSalesBandCom(params);


        List<Map<String,Object>>UserList=ListMapMergeUtil.ListMergeUtils(getAllUserIdAndName,getMarketSalesClinchCom,"userId");
        UserList=ListMapMergeUtil.ListMergeUtils(UserList,getMarketSalesBandCom,"userId");

        for(Map<String,Object> map:UserList){
            if(FieldCheckUtil.isMapFieldNotNull(map,new String[]{"heartCount"})&&
                    FieldCheckUtil.isMapFieldNotNull(map,new String[]{"bandCount"})){
                map.put("count",Arith.add(map.get("heartCount").toString(),map.get("bandCount").toString()).intValue());
            }else if(FieldCheckUtil.isMapFieldNotNull(map,new String[]{"heartCount"})){
                map.put("count",Arith.add(map.get("heartCount").toString(),"0").intValue());
                map.put("bandCount",0);
            }else if(FieldCheckUtil.isMapFieldNotNull(map,new String[]{"bandCount"})){
                map.put("count",Arith.add(map.get("bandCount").toString(),"0").intValue());
                map.put("heartCount",0);
            }else{
                map.put("count",0);
                map.put("heartCount",0);
                map.put("bandCount",0);
            }
        }


        //排序
        Collections.sort(UserList, new Comparator<Map<String, Object>>() {
            @Override
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                Integer count1=Integer.valueOf(o1.get("count").toString());
                Integer count2=Integer.valueOf(o2.get("count").toString());
                return count2.compareTo(count1);
            }
        });

        String userId=null;
        //排名
        for(int i=0;i<UserList.size();i++){
            userId=UserList.get(i).get("userId").toString();
            if(userId.equals(ContextUtils.getUserId().toString())){
                result.put("order",i+1);
                break;
            }
        }


        //只取10位最大
        List<Map<String,Object>>resultList=new ArrayList<Map<String,Object>>();
        for(int i=0;i<UserList.size();i++){
            if(i<=9){
                resultList.add(UserList.get(i));
            }
        }

        //排序
        Collections.sort(resultList, new Comparator<Map<String, Object>>() {
            @Override
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                Integer count1=Integer.valueOf(o1.get("count").toString());
                Integer count2=Integer.valueOf(o2.get("count").toString());
                return count1.compareTo(count2);
            }
        });

        //各人员名称
        List<String>chart1=new ArrayList<String>();
        //成交额
        List<String>chart2=new ArrayList<String>();
        //带看
        List<String>chart3=new ArrayList<String>();

        for(Map<String, Object> map:resultList){
            chart1.add(map.get("UserName").toString());
            chart2.add(map.get("heartCount").toString());
            chart3.add(map.get("bandCount").toString());
        }

        result.put("chart1",chart1);
        result.put("chart2",chart2);
        result.put("chart3",chart3);

        return result;
    }

    /**
     * 功能描述:
     * 获取市场部经理工作台的续租和续租率
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/7/22 14:28
     */
    public Map<String,Object>getRenewalPactCount(){
        Map<String,Object>result=new HashMap<String,Object>();
        //续签合同数
        double RenewalPactCount=Double.valueOf(RdPactMapper.getRenewalPactCount());
        //总合同数
        double RentCountPact=Double.valueOf(RdPactMapper.gerRentCountPact());
        if(RenewalPactCount>0){
            result.put("RenewalRate",Arith.mul(Arith.div(RenewalPactCount,RentCountPact,2),100.00));
        }else{
            result.put("RenewalRate",0);
        }
        result.put("RenewalPactCount",RenewalPactCount);
        return result;
    }
}
